<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-use strict'>/**
</span> * @fileOverview 滑块的键盘导航
 * @ignore
 */

&#39;use strict&#39;;

var $ = require(&#39;jquery&#39;),
  BUI = require(&#39;bui-common&#39;),
  CLS_HANDLE = &#39;x-slider-handle&#39;,
  CLS_START = CLS_HANDLE + &#39;-start&#39;,
  CLS_END = CLS_HANDLE + &#39;-end&#39;,
  NAV_TYPE = {
    START : 1,
    END : 0
  };

<span id='BUI-Slider-KeyNav'>/**
</span> * @class BUI.Slider.KeyNav
 * 列表导航扩展类
 */
var  KeyNav = function(){};

KeyNav.ATTRS = {
  
};

BUI.augment(KeyNav,{

  //获取滑动类型
  _getNavType : function(target){
    var sender = $(target);
    if(sender.hasClass(CLS_START)){
      return NAV_TYPE.START;
    }
    return NAV_TYPE.END;
  },
<span id='BUI-Slider-KeyNav-method-nextStep'>  /**
</span>   * 滑动到下一个点，跟step属性相关
   * @param  {Number} navType 1：start,0 : end
   */
  nextStep : function(navType){
    var _self = this,
      step = _self.get(&#39;step&#39;),
      max = _self.get(&#39;max&#39;)
      value = _self.get(&#39;value&#39;),
      newVal;
    if(BUI.isNumber(value)){
      _self.sliderTo(_self._getFrontValue(value + step));
      return;
    }
    if(navType){
      newVal = [_self._getFrontValue(value[0],value[1]),value[1]];
    }else{
      newVal = [value[0],_self._getFrontValue(value[1])];
    }
    _self.sliderTo(newVal);
  },
<span id='BUI-Slider-KeyNav-method-prevStep'>  /**
</span>   * 滑动到下一个点，跟step属性相关
   * @param  {Number} navType 1：start,0 : end
   */
  prevStep : function(navType){
    var _self = this,
      step = _self.get(&#39;step&#39;),
      value = _self.get(&#39;value&#39;),
      newVal;
    if(BUI.isNumber(value)){
      _self.sliderTo(_self._getBackValue(value - step));
      return;
    }
    if(navType){
      newVal = [_self._getBackValue(value[0]),value[1]];
    }else{
      newVal = [value[0],_self._getBackValue(value[1],value[0])];
    }
    _self.sliderTo(newVal);
  },
  _getBackValue : function(val,min){
    var _self = this;
    min = min || _self.get(&#39;min&#39;);
    return val &gt; min ? val : min;
  },
  _getFrontValue : function(val,max){
    var _self = this;
    max =  max || _self.get(&#39;max&#39;);
    return val &lt; max ? val : max;
  },
<span id='BUI-Slider-KeyNav-method-handleNavUp'>  /**
</span>   * 处理向上导航
   * @protected
   * @param  {jQuery.Event} ev 事件对象
   */
  handleNavUp : function (ev) {
    this.nextStep(this._getNavType(ev.target));
  },
<span id='BUI-Slider-KeyNav-method-handleNavDown'>  /**
</span>   * 处理向下导航
   * @protected
   * @param  {jQuery.Event} ev 事件对象
   */
  handleNavDown : function (ev) {
    this.prevStep(this._getNavType(ev.target));
  },
<span id='BUI-Slider-KeyNav-method-handleNavLeft'>  /**
</span>   * 处理向左导航
   * @protected
   * @param  {jQuery.Event} ev 事件对象
   */
  handleNavLeft : function (ev) {
    this.prevStep(this._getNavType(ev.target));
  },
  
<span id='BUI-Slider-KeyNav-method-handleNavRight'>  /**
</span>   * 处理向右导航
   * @protected
   * @param  {jQuery.Event} ev 事件对象
   */
  handleNavRight : function (ev) {
    this.nextStep(this._getNavType(ev.target));
  }
});

module.exports = KeyNav;
</pre>
</body>
</html>
